<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ page import="com.hzqy.web.vo.PmsUserVo"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<%@ taglib prefix="limits" uri="/WEB-INF/tld/limits.tld"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>分类添加</title>
<link rel="stylesheet" type="text/css"
	href="../../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"
	href="../../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"
	href="../../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="../../static/js/themes/icon.css">
	<link rel="stylesheet" type="text/css"	href="../../static/js/WdatePicker/skin/WdatePicker.css">
<script type="text/javascript" src="../../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="../../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../static/js/jquery.validate.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<script type="text/javascript" src="../../static/js/WdatePicker/WdatePicker.js"></script>
</head>
<body>
<%
PmsUserVo vo=((PmsUserVo)session.getAttribute("SESSION_USER"));
String roleId="0";
if(vo!=null){
	roleId=vo.getRoleIds();
}
String []nonceObj=ConstantUtils.getNonceObject();
%>
<div id="right" style="width: 100%; overflow: auto; float: right">
		<div id="container">
			<div class="editspace">
				<form id="contentForm" class="cmxform" enctype="multipart/form-data"
					name="formName">
					<input type="hidden" id="f_catalog_id" name="f_catalog_id" value="" />
					<input type="hidden" id="f_catalog_parentid" name="f_catalog_parentid" value="" />
					<input type="hidden" id="f_catalog_programatype" name="f_catalog_programatype" value="1" />
					<input type="hidden" name="stime" value="<%=nonceObj[0]%>"/>
					<input type="hidden" name="sign" value="<%=nonceObj[1]%>"/>
				
					<legend>分类新增</legend>
					<%if("1".equals(roleId)||"2".equals(roleId)) {//超级管理员角色时%>
										<fieldset class="hide">
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										产品包选择：
									</td>
									<td width="70%">
									 <select name="f_catalog_productid" id="f_catalog_productid" style="width: 150px;">
										</select>
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
					<%}else{%>
						<input type="hidden" id="f_catalog_productid" name="f_catalog_productid" value="1" /> 
					<%}%>		
					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										<span class="red">
											*
										</span>
										分类名称：
									</td>
									<td width="70%">
										<input type="text" name="f_catalog_name" id="f_catalog_name" style="width: 150px;" value=""/> 
									</td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										<span class="red">
											*
										</span>
										分类排序：
									</td>
									<td width="70%">
										<input type="text" name="f_catalog_viewindex" id="f_catalog_viewindex" style="width: 150px;" value=""/> 
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
					
				
					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										分类路径：
									</td>
									<td width="70%">
										<input type="text" name="f_catalog_url" id="f_catalog_url" style="width: 150px;" value=""/> 
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										<span class="red">*</span>组织选择:
									</td>
									<td width="70%">
										<input name="f_catalog_company_name" id="f_catalog_company_name" readonly="readonly"	style="width: 150px;" value="" class="yl_inp yw_name" />
										<input name="f_catalog_orgid" id="f_catalog_orgid" type="hidden" value="" />  
										<a id="12" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0);"
											onclick="bind();">选择</a>
									</td>
								</tr>
							</table>
						</div>
					</fieldset>

					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										<span class="red">
											*
										</span>
										分类状态：
									</td>
									<td width="70%">
										<select name="f_catalog_status" id="f_catalog_status" style="width: 150px;">
												<option value="1">有效</option>
												<option value="2">无效</option>
										</select>
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
					
					<limits:uiAuth url="showPasswordAndTime">
					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										是否开启密码：
									</td>
									<td width="70%">
										<select name="f_catalog_passwordstatus" id="f_catalog_passwordstatus" style="width: 150px;">
												<option value="0">否</option>
												<option value="1">是</option>
										</select>
									</td>
								</tr>
							</table>
						</div>
						
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										密码：
									</td>
									<td width="70%">
										<input type="password" name="f_catalog_password" id="f_catalog_password" style="width: 150px;" value=""/> 
									</td>
								</tr>
							</table>
						</div>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										开放时间：
									</td>
									<td width="70%">
										<input id="f_catalog_starttime" name="f_catalog_starttime" type="text" onClick="WdatePicker({skin:'default',dateFmt: 'yyyy-MM-dd HH:mm:ss'})" value="" class="yl_inp yw_name" />;
									</td>
								</tr>
							</table>
						</div>
						
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="right">
										关闭时间：
									</td>
									<td width="70%">
										<input id="f_catalog_endtime" name="f_catalog_endtime" type="text" onClick="WdatePicker({skin:'default',dateFmt: 'yyyy-MM-dd HH:mm:ss'})" value="" class="yl_inp yw_name" />;
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
					</limits:uiAuth>
					
					<fieldset>
						<div class="fitem">
							<table width="100%" border="0" cellpadding="0" cellspacing="0">
								<tr>
									<td width="30%" align="left">
										<jsp:include page="../../pictures/pictures_add_industry.jsp">
											<jsp:param name="picType" value="分类" />
										</jsp:include>
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
				</form>
			</div>
			<div class="toolbar" style="text-align: center;">
				<a id="easyui-linkbutton" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0);" onclick="_submitFm()">
					保存
				</a> 
				<a href="javascript:void(0);" data-options="iconCls:'icon-cancel'" class="easyui-linkbutton" onclick="javascript:parent.$('#dlg').dialog('close')">
					取消
				</a>
			</div>
		</div>
	</div> 
	<div id="org_list" class="easyui-dialog"
		style="width: 800px; height: 500px; padding-top: 0px;"
		data-options="title:'客户选择', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
</body>
<script type="text/javascript">
$(function(){
	$("#contentForm").validate({
		rules: {
			f_catalog_name: {
				required: true,
				minlength: 1,
				maxlength: 50
			},
			f_catalog_viewindex:{
				required:true
			},
			f_catalog_company_name:{
				required: true
			}
		},
		messages: {
			f_catalog_name: {
				required: "请输入分类名称",
				minlength: "分类名称不能少于1位",
				maxlength: "分类名称不能超过50位"
			},
			f_catalog_viewindex:{
				required: "请输入分类排序"
			},
			f_catalog_company_name:{
				required: "请选择组织",
			}
		},
		
	});
});
function GetRequest() {   
	   var url = location.search; //获取url中"?"符后的字串   
	   var theRequest = new Object();   
	   if (url.indexOf("?") != -1) {   
	      var str = url.substr(1);   
	      strs = str.split("&");   
	      for(var i = 0; i < strs.length; i ++) {   
	         theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);   
	      }   
	   }   
	   return theRequest;   
}  
window.onload=function(){
	<%if("1".equals(roleId)||"2".equals(roleId)) {//超级管理员角色时%>
		$.ajax({
			url:"../../product/product_list.do",
			data: {f_sp_status: 1, f_sp_id: 0 ,page:1 ,rows:1000},
			success:function(data) {
				data = JSON.parse(data).rows;
				var str = "";
				for(var i=0;i<data.length;i++) {
					str+='<option value="'+data[i].f_sp_id+'">'+data[i].f_sp_name+'</option>';
				}
				$("#f_catalog_productid").append(str);
			}
		}); 
	<%}%>		
 	
	var request=GetRequest();
	$("#f_catalog_id").val(0);
	$("#f_catalog_parentid").val(request.parentid);
	$("#f_catalog_name").val("");
	$("#f_catalog_viewindex").val(0);
	$("#f_catalog_url").val("");
	$("#f_catalog_desc").val("");
	$("#f_catalog_class").val("");
	$("#f_catalog_status").val(1);
	$("#f_catalog_passwordstatus").val(0);
	$("#f_catalog_password").val("");
	$("#f_catalog_starttime").val("");
	$("#f_catalog_endtime").val("");
}
function bind(){
	//openDialog($('#dlg'),'org_bind.jsp?chooseid='+$("#f_catalog_orgid").val());
	openDialog($('#org_list'),'../behavior_control/org_update.jsp?idField=f_catalog_orgid&nameField=f_catalog_company_name');
}
function _submitFm() {
	 arrayToJson();
	 if($("#contentForm").validate().form()) {
			app_ajax('../../catalog/insert_catalog.do', $("#contentForm").serialize(), function(data){
				if(data.success) {
					$.messager.progress('close');
					$.messager.alert('提示', '提交成功！', 'info', function() {
						$('#dlg').dialog('close');
						//parent.gotoSearch($('#easyui-treegrid'));
						window.location.reload();
					});
				} else {
					$.messager.alert('提示', data.result, 'info', function() {
						$.messager.progress('close');
					});
				}
			});	
	 }
	 window.parent.leftFrame.location.href = "catalog_list.jsp";
}
</script>
</html>